window.onload = ()=> {
    const videoMon = document.querySelector('#video');
    const saveBut = document.querySelector('.save');
    const cancelBut = document.querySelector('.cancel');
    let a
    window.preView.getData((videoUrl)=> {
        videoMon.src = videoUrl
        a = download(videoUrl, 'video')
        saveBut.appendChild(a)
    })

    saveBut.addEventListener('click', ()=> {
        // 下载
        a.click()
    })

    cancelBut.addEventListener('click', preViewClose)

    function preViewClose() {
        // video路径置为null
        videoMon.src = null
        //关闭预览页
        window.preView.closePreView()
    }
}


//下载
function download(url, fileName) {
    const nowDate = new Date().toISOString()
    const a = document.createElement('a')
    a.href = url
    a.download = `${fileName} ${nowDate}.webm`
    return a
}